<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\Db\Cursor;
use EasySwoole\ORM\Db\CursorInterface;
use EasySwoole\ORM\Exception\Exception;
use Throwable;

/**
 * Class UserOpenModel
 * Create With Automatic Generator
 * @property $id
 * @property $user_id
 * @property $user_type
 * @property $create_time
 * @property $certificate
 */
class UserOpenModel extends AbstractModel
{
    protected $tableName = 'bee_user_open';

    protected $primaryKey = 'id';

    protected $autoTimeStamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = false;

    /**
     * 添加用户第三方密钥
     * @param int $userId
     * @param string $openId
     * @param int $type
     * @return UserOpenModel|array|bool|AbstractModel|Cursor|CursorInterface|null
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws Exception
     * @throws Throwable
     */
    public function addUserOpen(int $userId,string $openId,  int $type)
    {
        $res = $this->data([
            'user_id' => $userId,
            'user_type' => $type,
            'create_time' => time(),
            'certificate' => $openId,
        ], false)->save();

        return $this->get($res);
    }
}